//
//  LGComposeToolBar.m
//  微博
//
//  Created by MS on 15-12-24.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGComposeToolBar.h"

@implementation LGComposeToolBar

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self setUpAllChildView];
    }
    return self;
    
}

-(void)setUpAllChildView
{
    //照片
    [self buttonWithImage:[UIImage imageNamed:@"compose_toolbar_picture"] andHighImage:[UIImage imageNamed:@"compose_toolbar_picture_highlighted"]];
    
    //@
    [self buttonWithImage:[UIImage imageNamed:@"compose_mentionbutton_background"] andHighImage:[UIImage imageNamed:@"compose_mentionbutton_background_highlighted"]];
    
    //话题
     [self buttonWithImage:[UIImage imageNamed:@"compose_trendbutton_background"] andHighImage:[UIImage imageNamed:@"compose_trendbutton_background_highlighted"]];
    
    //表情
     [self buttonWithImage:[UIImage imageNamed:@"compose_emoticonbutton_background"] andHighImage:[UIImage imageNamed:@"compose_emoticonbutton_background_highlighted"]];
    
    //键盘
     [self buttonWithImage:[UIImage imageNamed:@"compose_keyboardbutton_background"] andHighImage:[UIImage imageNamed:@"compose_keyboardbutton_background_highlighted"]];
  
    
}

-(void)buttonWithImage:(UIImage *)image andHighImage:(UIImage *)highImage {
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.tag = self.subviews.count;

    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:highImage forState:UIControlStateHighlighted];
    
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
}

-(void)btnClick:(UIButton *)btn
{
    if ([_delegate respondsToSelector:@selector(composeToolBar:didClickBtn:)]) {
        
        [_delegate composeToolBar:self didClickBtn:btn.tag];
    }
    
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    NSUInteger count = self.subviews.count;
    
    CGFloat x = 0;
     CGFloat y = 0;
     CGFloat w = self.width/count;
     CGFloat h = self.height;
    for (int i =0; i<count; i++) {
        x = w * i;
        UIButton * btn = self.subviews[i];
        btn.frame = CGRectMake(x, y, w, h);
        
    }
    
}

@end
